package com.yyds.controller;


import com.yyds.common.MyJSON;
import com.yyds.common.R;
import com.yyds.pojo.VaccineVaccine;
import com.yyds.service.VaccineVaccineService;
import com.yyds.vo.EchartPieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/vaccine/vaccine")
public class VaccineVaccineController {

    @Autowired
    @Qualifier("vaccineVaccineService")
    private VaccineVaccineService vaccineVaccineService;

    //添加疫苗种类
    @RequestMapping("/insertVaccine")
    public R insertVaccineVaccineController(VaccineVaccine vaccine) {
        Integer i = vaccineVaccineService.insertVaccineVaccineService(vaccine);
        return i > 0 ? R.ok() : R.error();
    }

    //删除疫苗种类
    @RequestMapping("/deleteVaccine")
    public R deleteVaccineVaccineController(Integer vaccine_id) {
        Integer i = vaccineVaccineService.deleteVaccineVaccineService(vaccine_id);
        return i > 0 ? R.ok() : R.error();
    }

    //删除部分疫苗种类
    @RequestMapping("/deleteAllVaccine")
    public R deleteAllVaccineVaccineController(String str) {
        System.out.println("deleteAllVaccineVaccineController str" + str);
        Integer i = vaccineVaccineService.deleteAllVaccineVaccineService(str);
        return i > 0 ? R.ok() : R.error();
    }

    //修改疫苗种类
    @RequestMapping("/updateVaccine")
    public R updateVaccineVaccineController(VaccineVaccine newVaccine) {
        System.out.println("updateVaccineVaccineController newVaccine = " + newVaccine);
        Integer i = vaccineVaccineService.updateVaccineVaccineService(newVaccine);
        return i > 0 ? R.ok() : R.error();
    }

    //查询全部疫苗种类
    @RequestMapping("/queryAllVaccine")
    public MyJSON<VaccineVaccine> queryAllVaccineVaccineController(@RequestParam Map<String, Object> map) {
        return vaccineVaccineService.queryVaccineVaccineService(map);
    }

    //查询疫苗品种类型
    @RequestMapping("/queryVaccineVarietyEchartPie")
    public R queryVaccineVarietyController(){
        List<EchartPieVo> list = vaccineVaccineService.queryVaccineVarietyService();
        return R.ok().data("pie", list);
    }

}
